package opengles;

import android.opengl.GLES20;
import android.opengl.GLES30;

/**
 * Created by freehyan on 9/9/2016.
 */
public class PBO {
    private int[] mPBOId;

    public void createPBO(int pboSize){
        mPBOId = new int[1];
        GLES30.glGenBuffers(1, mPBOId, 0);
        GLES30.glBindBuffer(GLES30.GL_PIXEL_PACK_BUFFER, mPBOId[0]);
        GLES30.glBufferData(GLES30.GL_PIXEL_PACK_BUFFER, pboSize, null, GLES30.GL_DYNAMIC_READ);
        GLES30.glBindBuffer(GLES30.GL_PIXEL_PACK_BUFFER, 0);
    }

    public int getPBOId(){
       return mPBOId[0];
    }

//    public void readPixelsFromFrameBuffer(int bufferId){
//        GLES30.glReadBuffer(GLES30.GL_COLOR_ATTACHMENT0);
//        GLES30.glBindBuffer(GLES30.GL_PIXEL_PACK_BUFFER, mPBOId[0]);
//        GLES30.glReadPixels(0, 0, width, height, GLES30.GL_RGBA, GLES30.GL_UNSIGNED_BYTE, 0);
//        GLubyte *ptr = GLES30.glMapBufferRange(GLES30.GL_PIXEL_PACK_BUFFER, 0, pbo_size, GLES30.GL_MAP_READ_BIT);
//        memcpy(pixels, ptr, pbo_size);
//        GLES30.glUnmapBuffer(GLES30.GL_PIXEL_PACK_BUFFER);
//        GLES30.glBindBuffer(GLES30.GL_PIXEL_PACK_BUFFER, 0);
//    }

}
